package com.research.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.research.common.R;
import com.research.entity.ResearchProject;
import com.research.service.ResearchProjectService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
@Slf4j
/*前端控制器*/
@RestController
@RequestMapping("/researchProject")
public class ResearchProjectController {

    @Resource
    private ResearchProjectService researchProjectService;

    @GetMapping("list")
    public R list(String keyword) {
        return R.success(researchProjectService.list(
                new QueryWrapper<ResearchProject>().like(keyword != null,"project_name", keyword).
                        or().like(keyword != null,"project_level", keyword).or().like(keyword != null,"project_category", keyword)
        ));

    }

    @PostMapping("save")
    public R save(@RequestBody ResearchProject researchProject) {
        log.info(researchProject.toString());
        return R.success(researchProjectService.save(researchProject));
    }

    @PostMapping("update")
    public R update(@RequestBody ResearchProject researchProject) {
        return R.success(researchProjectService.updateById(researchProject));
    }

    @PostMapping("delete")
    public R delete(Integer id) {
        return R.success(researchProjectService.removeById(id));
    }

    @GetMapping("detail")
    public R detail(Integer id) {
        return R.success(researchProjectService.getById(id));
    }
}

